<?php

namespace EShop\Controller;

/**
 * CartController 类
 *
 * @since VER:1.0; DATE:2016-8-29; AUTHOR:SoChishun; EMAIL:14507247@qq.com; DESC:Added.
 */
class CartController extends AppbaseMyController {

    function index() {
        $m_cart = new \XWAM\Model\ShoppingCartModel();
        $list = $m_cart->get_cart_paging_list($page, array('c.user_name' => $this->user_login_data['user_name']));
        $this->assign('list', $list);
        $this->assign('pager', $page->show());
        $this->display();
    }

    function get_cart_summary() {
        $m_cart = new \XWAM\Model\ShoppingCartModel();
        $result = $m_cart->get_cart_summary('', $this->user_login_data['user_name']);
        $this->ajaxReturn($result);
    }

    function add_cart($pid = 0, $n = 0) {
        if (!$pid || !$n || !is_numeric($pid) || !is_numeric($n)) {
            $this->ajaxReturn(array('status' => false, 'info' => '参数无效!'));
        }
        $m_cart = new \XWAM\Model\ShoppingCartModel();
        $result = $m_cart->add_cart($pid, $n, $this->user_login_data['user_name']);
        $this->ajaxReturn($result);
    }
    function clear_cart(){
        $m_cart = new \XWAM\Model\ShoppingCartModel();
        $m_cart->where(array('user_name'=>$this->user_login_data['user_name']))->delete();
    }

    function get_cart_count() {
        $m_cart = new \XWAM\Model\ShoppingCartModel();
        $n = $m_cart->get_count($this->user_login_data['user_name']);
        echo $n;
        exit;
    }

    function change_number($id = 0, $n = 0) {
        $m_cart = new \XWAM\Model\ShoppingCartModel();
        echo $m_cart->change_item_number($id, $n);
    }

    function delete_cart($id = 0) {
        if ($id) {
            $m_cart = new \XWAM\Model\ShoppingCartModel();
            $m_cart->delete($id);
        }
    }

    // 结算
    function checkout() {
        $this->display();
    }

    // 订单处理
    function done() {
        $this->display();
    }

    // 登录
    function login() {
        $this->display();
    }

    // 填写收货人信息
    function consignee() {
        $this->display();
    }

}
